from sqlalchemy import Column, BigInteger, Integer, String, DateTime
from sqlalchemy.ext.declarative import declarative_base
from datetime import datetime

Base = declarative_base()

class CmUser(Base):
    __tablename__ = 'cm_user'
    id = Column(BigInteger, primary_key=True, autoincrement=True, comment='id')
    source = Column(Integer, nullable=False, comment='1:扣子 2:微信')
    source_id = Column(String(100), nullable=True, comment='第三方用户ID')
    unionid = Column(String(100), nullable=True, comment='微信unionid')
    nickname = Column(String(100), nullable=True, comment='用户昵称')
    headimgurl = Column(String(500), nullable=True, comment='用户头像')
    created_at = Column(BigInteger, nullable=False, comment='创建时间')
    updated_at = Column(BigInteger, nullable=True, comment='更新时间')

    def user_to_dict(self):
        return {k: v for k, v in self.__dict__.items() if not k.startswith('_')}